The click manipulator is one of the input manipulators you can use to add gesture recognition to nodes in your Kanzi application. You can assign the input manipulators through the Kanzi Engine API. See Using input manipulators.
Enabling the click gesture for a node using Kanzi Studio
To enable the click gesture for a node using Kanzi Studio:
Select or create a node which you want to react to clicks. For example, create a Text Block 2D node.
In the Properties add and enable these properties:
Click Enabled When you enable this property you install a click manipulator which generates click messages. To instead create and configure a click manipulator using the Kanzi Engine API, see Enabling the click gesture for a node using the Kanzi Engine API.
Hit Testable When you enable this property you enable the user to pick a node.
In the Node Components > Triggers section add the Click trigger.
Click trigger is set off when the user presses down and then releases in the node area while the pointer is still within the node area.
Click Cancel trigger is set off:
When the user first presses down in the node area, then moves the pointer outside of the node area, and lifts the pointer.
When the user sets off a Long Press trigger.
Click Enter trigger is set off:
When the user presses down in the node area.
When the user presses down in the node area, moves the pointer outside of the node area, and then moves the pointer back to the node area while still holding down the pointer.
Click Leave trigger is set off:
When the user presses down in the node area and then lifts the pointer.
When the user sets off a Button: Long Press trigger.
When the user presses down in the node area and then moves the pointer outside of the node area.
Click Begin trigger is set off when the user presses down in the node area.
In the Node Components > Triggers in the Add dropdown menu for the Click trigger select an action. For example, select the Write Log action and enter a message you want to write to the Log window when the user clicks that node.
When you click the node which you set to react to Click events, the trigger sets off the action you defined in the trigger.
Enabling the click gesture for a node using the Kanzi Engine API
To enable the click gesture for a node using the Kanzi Engine API:
In Kanzi Studio create a project using the Application template.
In the Project create a node for which you want to enable the click gesture. For example, create an Empty Node 2D node, name it ClickNode, and add content to the node.
In the Project select the node you created in the previous step, in the Properties add the Hit Testable property, and set it to enabled. When you enable this property you enable the user to pick a node.
In the Projectpress Alt and right-click the node you created and select Alias. Kanzi Studio creates an alias pointing to the node from which you created the alias and adds it to the resource dictionary of its nearest ancestor node that contains a resource dictionary. Access alias target nodes using the # sign followed by the name of the alias.
Select File > Export > Export KZB. Kanzi Studio creates the kzb file and configuration files from your Kanzi Studio project. Kanzi Studio stores the exported files in <KanziWorkspace>/Projects/<ProjectName>/Application/bin or the location you specify in the Binary Export Directory property in Project > Properties. The kzb file contains all nodes and resources from your Kanzi Studio project, except the resources you mark in a localization table as locale packs. When you run your Kanzi application from Visual Studio, your Visual Studio solution reads these files to create your Kanzi application.
In Visual Studio open the solution stored in <ProjectName>/Application/configs/platforms/win32 and in the file which implements the logic of your application create and configure the click manipulator:
Create the handlers for different click messages. In each handler add the code that defines the behavior for a specific click event. You can define the behavior also in Kanzi Studio using the click triggers. See Reacting to the click gesture you enabled with the Kanzi Engine API. For example, to create handlers for the ClickMessage and ClickCancelMessage messages, after the public section of the class which implements the logic of your application add:
private:
// Create the handler for the ClickManipulator::ClickMessage message from the nodes
// that have an input manipulator which generates the ClickMessage message.
void onNodeClicked(ClickManipulator::ClickMessageArguments& messageArguments)
{
// Add the code that handles the click event.
}
// Create the handler for the ClickManipulator::ClickCancelMessage message from the nodes
// that have an input manipulator which generates the ClickCancelMessage message.
void onNodeClickCanceled(ClickManipulator::ClickCancelMessageArguments& messageArguments)
{
// Add the code that handles the click cancel event.
}
In the onProjectLoaded() function create a ClickManipulator manipulator and subscribe to its messages. For example, add:
virtual void onProjectLoaded() KZ_OVERRIDE
{
ScreenSharedPtr screen = getScreen();
Domain* domain = getDomain();
// Get the ClickNode node using its alias.
NodeSharedPtr clickNode = screen->lookupNode<Node>("#ClickNode");
// Create an input manipulator that generates click messages.
ClickManipulatorSharedPtr clickManipulator = ClickManipulator::create(domain);
// Add the input manipulator to the ClickNode node.
clickNode->addInputManipulator(clickManipulator);
// Subscribe to the ClickManipulator::ClickMessage message at the ClickNode node.
// The ClickManipulator manipulator generates this message when the user clicks the node.
clickNode->addMessageHandler(ClickManipulator::ClickMessage, bind(&MyProject::onNodeClicked, this, placeholders::_1));
// Subscribe to the ClickManipulator::ClickCancelMessage message at the ClickNode node.
// The ClickManipulator manipulator generates this message when the user first presses down
// the node, then moves the pointer outside of the node area, and lifts the pointer.
clickNode->addMessageHandler(ClickManipulator::ClickCancelMessage, bind(&MyProject::onNodeClickCanceled, this, placeholders::_1));
}
Click the node for which you enabled the click gesture. The application executes the behavior you defined in the handler for the ClickMessage message.
Press down the node for which you enabled the click gesture, then move the pointer outside of the node area, and lift the pointer. The application executes the behavior you defined in the handler for the ClickCancelMessage message.
Reacting to the click gesture you enabled with the Kanzi Engine API
This section explains how to use the click triggers to react to the click gesture when you enable the click gesture for a node using the Kanzi Engine API. To learn how to create a node that reacts to clicks using only Kanzi Studio, see Enabling the click gesture for a node using Kanzi Studio.
Use the Click triggers to react to the click gesture. For example, you can change the appearance of a node when the user clicks or taps that node.
Kanzi Studio has these click triggers:
Click trigger is set off when the user presses down and then releases in the node area while the pointer is still within the node area.
Click Begin trigger is set off when the user presses down in the node area.
Click Cancel trigger is set off:
When the user first presses down in the node area, then moves the pointer outside of the node area, and lifts the pointer.
When the user sets off a Long Press trigger.
Click Enter trigger is set off:
When the user presses down in the node area.
When the user presses down in the node area, moves the pointer outside of the node area, and then moves the pointer back to the node area while still holding down the pointer.
Click Leave trigger is set off:
When the user presses down in the node area and then lifts the pointer.
When the user sets off a Button: Long Press trigger.
When the user presses down in the node area and then moves the pointer outside of the node area.
Define the behavior that you want to set with the click triggers. For example, create a state manager where you define the states which set the appearance of a node when different click triggers are set off. See Adding a state manager to your project.
Add and configure a click trigger:
In the Project select the node to which you want to add the trigger, and in the Node Components > Triggers section add one of the click triggers. For example, in the Project select the node for which you enabled the click gesture and in the Node Components add the Click trigger.
In the trigger you created in the previous step click Trigger Settings and in the Trigger Settings Editor disable the Set Message Handled property. When you disable the Set Message Handled property, this trigger intercepts the message, but does not stop it. This way you let the input manipulator handle the message.
In the trigger you created, in the Add dropdown menu select an action and configure it. For example, select the Go to State action, and in the action settings set:
Item to the node for which you enabled the click gesture
State to the state which sets the appearance of the node when the Click trigger is set off
Repeat the previous step to add and configure more click triggers. For example, add the Click Cancel trigger, and in the Go to State action of the trigger set State to the state which sets the appearance of the node when that trigger is set off.
Select File > Export > Export KZB.
Build and run your application. See Deploying Kanzi applications. In the application click or tap the node for which you enabled the click gesture.